<?php
// ****************************************************
// PHP for XUploadFiles 2.1.0.0
// 程序制作：blue999.com
// 版权所有：blue999.com
// 主页地址：http://www.blue999.com/xuploadfiles/
// 程序申明：用于商业应用时请与作者联系
// 最后修改：2005.11.16
// ****************************************************
class XUpload_class{
var $SFNHV,$RYXYV,$UVBWH,$ZFSKG,$ITLUT,$GIONB,$TLRKK,$XASTU,$RRUGY,$RXZWA,$CANBM,$JEGUI,$IXIZC,$MJKVP;

function GetVersion(){ return $this->SFNHV; }
function IsError(){ return $this->RYXYV; }
function SetOverlayMode($value){ $this->UVBWH=$value; }
function SetMinFileSize($value){ $this->ZFSKG=$value; }
function SetMaxFileSize($value){ $this->ITLUT=$value; }
function SetMaxFileCount($value){ $this->GIONB=$value; }
function SetMaxTotalSize($value){ $this->TLRKK=$value; }
function SetAllowExt($value){ $this->XASTU=strtolower(trim($value)); if($this->XASTU!="") $this->XASTU=";" . $this->XASTU . ";"; }
function SetDenyExt($value){ $this->RRUGY=strtolower(trim($value)); if($this->RRUGY!="") $this->RRUGY=";" . $this->RRUGY . ";"; }
function SetThumbImage($value){ $this->RXZWA=trim($value); }
function SetStatURL($value){ $this->CANBM=trim($value); }
function HasThumbImage(){ return $_POST['xu_thumbtag']=="thumb"; }
function OutErr($message){ $this->RYXYV=true; print($message); }
function Out($message){ if(!$this->RYXYV && !$this->IXIZC){ $this->IXIZC=true; print("ok"); } print($this->JEGUI); print($message); }
function XUpload_class(){$this->SFNHV=2100;$this->RYXYV=false;$this->SetOverlayMode(false);$this->SetMinFileSize(1);$this->SetMaxFileSize(10485760);$this->SetMaxFileCount(100);$this->SetMaxTotalSize(10485760);$this->SetAllowExt("");$this->SetDenyExt("asa;asp;cdx;cer;aspx;php");$this->SetThumbImage("");$this->SetStatURL("");$this->JEGUI=Chr(7);$this->IXIZC=false;$this->MJKVP="upfiles/xu_temp_/";}
function InitParameters(){if($this->RYXYV) return;if(!is_writable($this->MJKVP . "."))$this->OutErr("临时文件夹没有写的权限，不能进行文件操作。");else if($_POST['xu_version'] < $this->SFNHV)$this->OutErr("您的上传插件版本太低，请升级到最新版本。");else if(preg_match("/\D/",$_POST['xu_verifier']) || preg_match("/[\/|\\\\]/",$_POST['xu_tag']))$this->OutErr("发送的数据格式不正确。");else if($_POST['xu_operate']=="init"){if(!file_exists($this->MJKVP)) mkdir($this->MJKVP);$this->Out($this->SFNHV);$this->Out($this->ZFSKG);$this->Out($this->ITLUT);$this->Out($this->GIONB);$this->Out($this->TLRKK);$this->Out($this->XASTU);$this->Out($this->RRUGY);$this->Out($this->RXZWA);$this->Out($this->CANBM);$this->RYXYV=true;}else if($_POST['xu_operate']=="postclose"){$LNTWN=$_POST['xu_tag'];if($LNTWN!="" && $LNTWN!="0"){$YUWNZ=$this->MJKVP . $_POST['xu_verifier'] . $LNTWN . ".t";if(file_exists($YUWNZ)) unlink($YUWNZ);$YUWNZ=$this->MJKVP . $_POST['xu_verifier'] . $LNTWN . "thumb" . ".t";if(file_exists($YUWNZ)) unlink($YUWNZ);}$this->Out("ok");$this->RYXYV=true;}}
function IsUploadFile(){if($this->RYXYV) return false;switch($_POST['xu_operate']){case "postdata":$LNTWN=$_POST['xu_tag'];if($LNTWN=="0" ||($LNTWN=="" && $_POST['xu_desc']!="") ||($LNTWN!="" && $_POST['xu_length']==0) ||($LNTWN!="" && $_POST['xu_offset']==0 && $_POST['xu_desc']=="") ||preg_match("/[\/|\\\\|\.]/",$_POST['xu_desc']) ||$_FILES['xu_postfile']['size']!=$_POST['xu_length'] ||$_POST['xu_offset'] + $_POST['xu_length'] > $_POST['xu_filelength']){$this->OutErr("发送的数据格式不正确。");return false;}if($_POST['xu_filelength'] < $this->ZFSKG){$this->OutErr("上传文件的长度小于服务器的最小限制。");return false;}if($_POST['xu_filelength'] > $this->ITLUT){$this->OutErr("上传文件的长度超过服务器限制。");return false;}if($LNTWN=="" && !$this->NVKWL($_FILES['xu_postfile']['name'])){$this->OutErr("服务器不接受该类型的文件。");return false;}$WAMEJ=$this->MJKVP . $_POST['xu_verifier'] . $LNTWN . $_POST['xu_desc'] . ".t";if($LNTWN==""){if($_POST['xu_length']==0){$LNTWN="0";} else{$LNTWN=basename($_FILES['xu_postfile']['tmp_name']) . "xu";$WAMEJ=$this->MJKVP . $_POST['xu_verifier'] . $LNTWN . $_POST['xu_desc'] . ".t";}}if($_POST['xu_length'] > 0){if($_POST['xu_offset']==0){if(!move_uploaded_file($_FILES['xu_postfile']['tmp_name'],$WAMEJ)){$this->OutErr("上传文件非法，请重新进行操作。");return false;}} else{if(!file_exists($WAMEJ)){$this->OutErr("原始数据被服务器清除了，请重新进行操作。");return false;}if(filesize($WAMEJ)!=$_POST['xu_offset']){$this->OutErr("数据参数有问题，不能进行上传。");return false;}$HVMXT=fopen($_FILES['xu_postfile']['tmp_name'],"rb");$QOGLZ=fread($HVMXT,$_FILES['xu_postfile']['size']);fclose($HVMXT);$HVMXT=fopen($WAMEJ,"ab");$BRIMT=fwrite($HVMXT,$QOGLZ);fclose($HVMXT);if($BRIMT!=$_FILES['xu_postfile']['size']){$this->OutErr("服务器保存数据出现错误，请重新进行操作。");return false;}}}$this->Out($LNTWN);$this->RYXYV=true;break;case "postfile":break;default:$this->OutErr("服务器不支持该命令。");break;}return !$this->RYXYV;}
function SaveToFile($WAMEJ){if($this->RYXYV || $WAMEJ=="") return "";if(!$this->NVKWL($WAMEJ)){$this->OutErr("服务器不接受该类型文件。");return "";}if($_POST['xu_filesize'] < $this->ZFSKG){$this->OutErr("上传文件的长度小于服务器的最小限制。");return false;}if($_POST['xu_filesize'] > $this->ITLUT){$this->OutErr("上传文件的长度超过服务器限制。");return "";}if(!$this->UVBWH){$TKJHE=strrchr(basename($WAMEJ),'.');$WAMEJ=substr($WAMEJ,0,strlen($WAMEJ)-strlen($TKJHE)) . "-";srand(time());$QFUVY=(rand() % 9000) + 1000;for($GMFBA=0; $GMFBA < 100; $GMFBA++){$QFUVY=(rand() % 9000) + 1000;if(!file_exists($WAMEJ . $QFUVY . $TKJHE)) break;}$WAMEJ=$WAMEJ . $QFUVY . $TKJHE;}if(!$this->YCFDY($WAMEJ)){$this->OutErr("服务器不接受该类型文件。");return "";}if($_POST['xu_tag']=="0"){fclose(fopen($WAMEJ,"wb"));} else{$YUWNZ=$this->MJKVP . $_POST['xu_verifier'] . $_POST['xu_tag'] . ".t";if(!file_exists($YUWNZ) || $_POST['xu_filesize']!=filesize($YUWNZ)){$this->OutErr("发送的数据格式不正确。");return "";}if(file_exists($WAMEJ)) unlink($WAMEJ);if(!rename($YUWNZ,$WAMEJ)){$this->OutErr("目标文件夹没有写的权限，不能进行文件操作。");return "";}}return $WAMEJ;}
function SaveThumbToFile($WAMEJ){$YUWNZ=$this->MJKVP . $_POST['xu_verifier'] . $_POST['xu_tag'] . $_POST['xu_thumbtag'] . ".t";if($this->RYXYV || $WAMEJ=="" ||!$this->NVKWL($WAMEJ) ||!$this->HasThumbImage() ||$_POST['xu_tag']=="0" ||$_POST['xu_thumbsize']==0 || $_POST['xu_thumbsize'] > $this->ITLUT ||!file_exists($YUWNZ) || $_POST['xu_thumbsize']!=filesize($YUWNZ)){return "";}if(!$this->YCFDY($WAMEJ)) return "";if(file_exists($WAMEJ)) unlink($WAMEJ);if(!rename($YUWNZ,$WAMEJ)) return "";return $WAMEJ;}
function CreateFileName($IYPOT,$WFLBF,$WAMEJ){$WAMEJ=basename($WAMEJ);if(!(strpos($WFLBF,'.') === false)){$this->OutErr("路径或文件名中包含有非法字符");return "";}if($IYPOT!=""){$ADKMZ=$IYPOT{strlen($IYPOT)-1};if($ADKMZ!='\\' && $ADKMZ!='/') $IYPOT .= "\\";}if($WFLBF!=""){if($WFLBF{0}=='\\' || $WFLBF{0}=='/') $WFLBF=substr($WFLBF,1);}if($WFLBF!=""){$ADKMZ=$WFLBF{strlen($WFLBF)-1};if($ADKMZ!='\\' && $ADKMZ!='/') $WFLBF .= "\\";}return str_replace("\\","/",$IYPOT . $WFLBF . $WAMEJ);}
function CreateFileURL($IYPOT,$WFLBF,$WAMEJ){$WAMEJ=basename($WAMEJ);if($IYPOT=="") $IYPOT="./";if(strpos($IYPOT,':') === false){$ADKMZ=$IYPOT{strlen($IYPOT)-1};if($ADKMZ!='\\' && $ADKMZ!='/') $IYPOT .= "/";} else{$IYPOT="/*内部地址*/";}if($WFLBF!=""){if($WFLBF{0}=='\\' || $WFLBF{0}=='/') $WFLBF=substr($WFLBF,1);}if($WFLBF!=""){$ADKMZ=$WFLBF{strlen($WFLBF)-1};if($ADKMZ!='\\' && $ADKMZ!='/') $WFLBF .= "/";}return str_replace("\\","/",stripslashes($IYPOT . $WFLBF . $WAMEJ));}
function NVKWL($WAMEJ){$TKJHE=trim(strtolower(substr(strrchr(basename($WAMEJ),'.'),1)));if($TKJHE!=""){$TKJHE=";" . $TKJHE . ";";if($this->XASTU!=""){ if(strpos($this->XASTU,$TKJHE) === false) return false; }else if($this->RRUGY!=""){ if(!(strpos($this->RRUGY,$TKJHE) === false)) return false; }} else if($this->XASTU!=""){ return false; }return true;}
function YCFDY($WAMEJ){$TKJHE=strstr(basename($WAMEJ),'.');if($TKJHE=="") return true;$IWURR=$this->MJKVP . $_POST['xu_tag'] . "tmp.t";fclose(fopen($IWURR . $TKJHE,"wb"));$DZIMS=false;foreach(glob($IWURR . ".*") as $WAMEJ){if(strcasecmp($WAMEJ,$IWURR . $TKJHE)==0){$DZIMS=true;break;}}if(file_exists($IWURR . $TKJHE)) unlink($IWURR . $TKJHE);return $DZIMS;}} 
?>